package com.tools;

import android.content.Context;
import android.util.DisplayMetrics;

public class MultipleScreenTool {

	/**
	 * ��Ļ����
	 * 
	 * @author ������
	 */
	public static enum ScreenCategory {
		smallScreens, normalScreens, largeScreens, xlargeScreens,
	}

	/**
	 * �жϴ��豸�ķֱ��ʵķ���
	 * 
	 * @param context
	 * @return
	 */
	public static ScreenCategory getScreenCategory(Context context) {

		DisplayMetrics displayMetrics = context.getResources()
				.getDisplayMetrics();

		int wd = (int) (displayMetrics.widthPixels / displayMetrics.density + 0.5);
		int hd = (int) (displayMetrics.heightPixels / displayMetrics.density + 0.5);

		if (wd < hd) {
			int tmp = wd;
			wd = hd;
			hd = tmp;
		}

		if (wd >= 960 && hd >= 720) {

			return ScreenCategory.xlargeScreens;

		} else if (wd >= 640 && hd >= 480) {
			return ScreenCategory.largeScreens;
		} else if (wd >= 470 && hd >= 320) {
			return ScreenCategory.normalScreens;
		} else {
			return ScreenCategory.smallScreens;
		}

	}

	/**
	 * dpת������
	 * 
	 * @param dp
	 * @param context
	 * @return
	 */
	public static int dpTopx(float dp, Context context) {
		DisplayMetrics displayMetrics = context.getResources()
				.getDisplayMetrics();

		System.out.println("dpTopx" + (dp * displayMetrics.density + 0.5));

		return (int) (dp * displayMetrics.density + 0.5);
	}

}
